package com.class05.fruit.servlets;

import com.class05.fruit.dao.FruitDAO;
import com.class05.fruit.dao.impl.FruitDAOImpl;
import com.class05.fruit.pojo.Fruit;
import com.class05.myssm.myspringmvc.ViewBaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/add.do")
public class AddServlet extends ViewBaseServlet {
    private FruitDAO fruitDao = new FruitDAOImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String fname = req.getParameter("fname");
        //方式一:Integer和int拆箱.装箱过程

        //Integer price = Integer.valueOf(req.getParameter("price"););
        //方式二:
        Integer price=Integer.parseInt(req.getParameter("price"));
        Integer fcount = Integer.parseInt(req.getParameter("fcount"));
        String remark = req.getParameter("remark");
        fruitDao.addFruit(new Fruit(0, fname, price, fcount, remark));

        response.sendRedirect("index");
    }
}
